package code.twopoint;

import java.util.Arrays;

public class 反转字符串java {
    public static void main(String[] args) {
        System.out.println(reverseWords("Let's take LeetCode contes"));
    }

    public  static void reverseString(char[] s) {
        int left = 0;
        int right = s.length - 1;
        while (left <= right) {
            char temp = s[left];
            s[left] = s[right];
            s[right] = temp;
            left++;
            right--;
        }
    }

    public static String reverseWords(String s) {
        StringBuilder sb = new StringBuilder();
        String[] items = s.split(" ");
        for (int i = 0; i < items.length; i++) {
            String item = items[i];
            char[] it = item.toCharArray();
            reverseString(it);
            sb.append(it);
            if (i!=items.length-1){
                sb.append(" ");
            }
        }
        return sb.toString();
    }
}
